package com.hyp.mapper;

import com.hyp.pojo.Address;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressMapper {
    @Insert("insert into address (UserID, AddressName, UserName,Phone,IsDefault, CreatedAt, UpdatedAt) " +
            "VALUES (#{userId}, #{addressName},#{userName},#{phone},#{isDefault},#{createdAt},#{updatedAt})")
    void addressAdd(Address address);
    @Update("update address set IsDefault = #{isDefault}, UpdatedAt = #{updatedAt} where addressId = #{addressId}")
    void update(Address address);
    @Select("select * from address where UserID = #{userId} and IsDefault = true")
    Address findDefaultByUserId(Integer userId);

    @Select("select * from address where UserID = #{userId} order by CreatedAt desc")
    List<Address> list(Integer userId);

    @Select("select * from address where AddressID = #{addressId}")
    Address addressById(Integer addressId);
}
